﻿using System;
using System.Text;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.Administration;
using ServBus.ListForm2013.Controls;
using ServBus.ListForm2013.License;
using ServBus.ListForm2013.Resources;

namespace ServBus.ListForm2013.AdministrationPages
{
    public partial class GetServerInfo : System.Web.UI.Page
    {
        #region Controls
        protected BreadCrumbNav bcNav;
        protected Literal ltScript;
        protected CheckBoxList cblServers;
        #endregion

        private static DllResource Resource = new DllResource("ServBus.ListForm2013.Common.Resources|AdminPages");

        protected void Page_Load(object sender, EventArgs e)
        {
            // Nav
            bcNav.AddLink(Resource.GetString("License_Nav"), "License.aspx", null);
            bcNav.AddLink(Resource.GetString("Server_Info_Nav"), null, null);

            if (!IsPostBack)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append("<script type='text/javascript'>_serverIds=[''");
                ListItem li = new ListItem(Resource.GetString("Server_All"), "");
                li.Selected = true;
                cblServers.Items.Add(li);

                foreach (SPServer server in FarmInfo.GetFrontEndServers())
                {
                    builder.AppendFormat(",'{0}'", server.Id.ToString());
                    ListItem liServer = new ListItem(server.Name, server.Id.ToString());
                    liServer.Selected = true;
                    cblServers.Items.Add(liServer);
                }

                builder.Append("];</script>");
                ltScript.Text = builder.ToString();
            }
        }
    }
}
